package com.yk.anima.controller;

import com.yk.anima.api.OrdersApi;
import com.yk.anima.pojo.Orders;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.OrdersServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 22:44:38
 * @desc... 订单管理
 */

@RestController
@RequestMapping("/order")
public class OrdersController implements OrdersApi {


    @Autowired
    OrdersServlet ordersServlet;

    /**
     * @param
     * @return java.util.List<com.yk.anima.pojo.Orders>
     * @Author xiaoKai
     * @Description 订单查询
     * @Date 10:27 2021/5/14
     */
    @Override
    @GetMapping("/findAll/{orderAdminId}")
    public List<Orders> findAll(@PathVariable("orderAdminId") int orderAdminId) {
        return ordersServlet.findAll(orderAdminId);
    }

    /**
     * @param orderAdminId 购物车属于那个用户
     * @param id           购物车中当前猫的ID
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description
     * @Date 11:19 2021/5/14
     */
    @Override
    @PostMapping("/save/{orderAdminId}/{id}")
    public ResponseResult save(int orderAdminId, int id) {
        return ordersServlet.save(orderAdminId, id);
    }

    /**
     * @param size
     * @param page
     * @param animalName
     * @return com.yk.anima.response.QueryResponseResult
     * @Author xiaoKai
     * @Description 根据宠物名称模糊查询
     * @Date 17:34 2021/5/14
     */
    @Override
    @GetMapping("/findByPage/{page}/{size}")
    public QueryResponseResult likeName(@PathVariable("page") int page,
                                        @PathVariable("size") int size, String animalName) {

        return ordersServlet.likeName( page,size, animalName);
    }
    /**
     * @Author xiaoKai
     * @Description
     * @Date 18:13 2021/5/16
     * @param oId 当前宠物ID
     * @param orderAdminId  用户ID
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @DeleteMapping("/deleteById/{oId}/{orderAdminId}")
    public ResponseResult deleteById(@PathVariable("oId") int oId,@PathVariable("orderAdminId") int orderAdminId) {
        return ordersServlet.deleteById(oId,orderAdminId);
    }


}
